/********************************************************************************
* File Name:	mainwindow.cpp
* Description:	第3章 实例1：PushButton、RadioButton和CheckBox控件的综合实例
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
*
********************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btn_RadioButton_clicked()
{
      ui->radioButton->setChecked(true);
      ui->label->setText("RadioButton1 is Checked!");
}

void MainWindow::on_btn_CheckBox_clicked()
{
    QString str;
    str ="";
    ui->label_2->adjustSize();
    if(ui->checkBox->isChecked())
    {
        str += "checkBox1 is Checked;\n";
    }
    if(ui->checkBox_2->isChecked())
    {
        str += "checkBox2 is Checked;";
    }
    if(ui->checkBox_3->isChecked())
    {
        str +="checkBox3 is Checnked!";
    }
    ui->label_2->setText(str);
}

void MainWindow::on_radioButton_clicked()
{
    ui->radioButton->setChecked(true);
    ui->label->setText("RadioButton1 is Checked!");
}

void MainWindow::on_radioButton_2_clicked()
{
    ui->radioButton_2->setChecked(true);
    ui->label->setText("RadioButton2 is Checked!");
}

void MainWindow::on_radioButton_3_clicked()
{
    ui->radioButton_3->setChecked(true);
    ui->label->setText("RadioButton3 is Checked!");
}

void MainWindow::on_checkBox_clicked()
{
    if(ui->checkBox->isChecked())
    {
        this->displayCheckBox();
    }
    else
    {
        this->displayCheckBox();
    }
}

void MainWindow::on_checkBox_2_clicked()
{
    if(ui->checkBox_2->isChecked())
    {
        this->displayCheckBox();
    }
    else
    {
        this->displayCheckBox();
    }
}

void MainWindow::on_checkBox_3_clicked()
{
    if(ui->checkBox_3->isChecked())
    {
        this->displayCheckBox();
    }
    else
    {
        this->displayCheckBox();
    }
}
void MainWindow::displayCheckBox()
{
    QString str;
    str ="";
    //ui->label_2->adjustSize();
    if(ui->checkBox->isChecked())
    {
        str += "checkBox1 is Checked;";
    }
    if(ui->checkBox_2->isChecked())
    {
        str += "checkBox2 is Checked;";
    }
    if(ui->checkBox_3->isChecked())
    {
        str +="checkBox3 is Checnked!";
    }
    ui->label_2->setText(str);
}
